package com.hq.admin.web;

import javax.servlet.http.HttpServletRequest;

import com.hq.base.service.BaseService;
import com.hq.base.web.BaseController;
import com.hq.common.domain.Const;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.hq.admin.domain.Operator;
import com.hq.admin.service.OperatorService;
import com.hq.common.domain.Result;
import com.hq.common.domain.ResultCode;

/**
 * Created by hezj on 2015/7/3 0003.
 */

@Controller
@RequestMapping("/rest/admin")
public class OperatorController extends BaseController {
    @Autowired
    private OperatorService operatorService;

    @RequestMapping("login")
    @ResponseBody
    public Result login(@RequestParam("userName")String userName,@RequestParam("userPassword")String userPassword,HttpServletRequest request){
        Operator operator = operatorService.login(userName, userPassword);
        request.getSession().setAttribute(Const.Operator_Session,operator);
        if(operator ==null){
            return getResult(ResultCode.NOT_FOUND,"用户名或者密码错误。");
        }
        return getResult();
    }

    @RequestMapping("mvc/index")
    public ModelAndView index(HttpServletRequest request){
        return new ModelAndView("admin/index");
    }

    @Override
    public BaseService getService() {
        return operatorService;
    }
}
